package com.glsc.ngateway.common.base.repo.mysql.gateway.platform;

import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.UserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

/**
 * 功能描述: <br>
 *
 * @author gaojc
 * @date 2020/12/7 15:17
 */
public interface UserRoleRepo extends JpaRepository<UserRole, Long>, JpaSpecificationExecutor<UserRole> {

    @Transactional
    @Modifying
    @Query(value = "delete from UserRole r where r.roleId = :id")
    int deleteById(@Param("id") long id);

    @Transactional
    @Modifying
    @Query(value = "insert into t_user_role(user_id, role_id) value(:userId, :roleId)", nativeQuery = true)
    void addUserRole(@Param("userId") long userId, @Param("roleId") long roleId);

    @Transactional
    @Modifying
    @Query(value = "delete from t_user_role where user_id = :userId and role_id = :roleId", nativeQuery = true)
    void deleteUserRole(@Param("userId") long userId, @Param("roleId") long roleId);
}
